package com.hbter630.change.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbter630.change.entity.Product;
import com.hbter630.change.mapper.ProductMapper;
import com.hbter630.change.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbter630.change.utils.Result;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xbfinal
 * @since 2023-05-24
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {


    @Override
    public Result alllistByPage(long current, long limit) {
        Page<Product> productPage = new Page<Product>(current, limit);

        Page<Product> productPage1 = baseMapper.selectPage(productPage, null);

        return Result.ok().addData(productPage1);
    }

    @Override
    public void updateNew(Product product) {
        Integer productId = product.getProductId();
        if(productId != null){
            //更新操作
            baseMapper.updateById(product);
            return;
        }
        //保存操作
        this.save(product);
    }
}
